package com.hdax.dm.scheduler.mappers;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hdax.dm.entity.scheduler.SchedulerSeat;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SchedulerSeatMapper extends BaseMapper<SchedulerSeat> {
    @Select({
            "<script>",
            "select p.price,s.* from dm_scheduler_seat s,dm_scheduler_seat_price p",
            " where s.scheduleId = p.scheduleId and s.areaLevel = p.areaLevel",
            "<if test='isNotAll'>",
            " and s.orderNo is null and s.userId is null and s.status = 1",
            "</if>",
            " and s.scheduleId=#{scheduleId}",
            "</script>"
    })
    List<SchedulerSeat> seats(@Param("scheduleId")Long scheduleId, @Param("isNotAll")Boolean isNotAll);

    @Update(
            "update dm_scheduler_seat set orderNo =#{seat.orderNo} ," +
                    "userId =#{seat.userId},status = 2 where X=#{seat.x} and Y=#{seat.y} and scheduleId=#{seat.scheduleId}"
    )
    int updateSeat(@Param("seat") SchedulerSeat seat);

    @Update({
            "update dm_scheduler_seat",
            " set orderNo = null,",
            " userId = null,",
            " status = 1",
            " where orderNo = #{orderNo}"
    })
    int updateSeat2(@Param("orderNo")String orderNo);

    @Update({
            "update dm_scheduler_seat",
            " set status=3",
            " where orderNo = #{orderNo}"
    })
    int sold(@Param("orderNo")String orderNo);

    @Update({
            "update dm_scheduler_seat",
            " set orderNo = null,",
            " userId = null,",
            " status = 1",
            " where orderNo = #{orderNo}"
    })
    int updateSeatOne(@Param("orderNo")String orderNo);

    @Update({
            "update dm_scheduler_seat",
            " set status = 3",
            " where orderNo = #{orderNo}"
    })
    int updateSeatTwo(@Param("orderNo")String orderNo);
}
